<!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
  <title>天量科技管理后台</title>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width">
  <link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="stylesheet" href="css/templatemo_main.css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body ng-app="app" ng-controller="index">
<div class="navbar navbar-inverse" role="navigation">
  <div class="navbar-header">
    <div class="logo"><h1>天量科技管理后台</h1></div>
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
      <span class="sr-only">Toggle navigation</span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </button>
  </div>
</div>
<div class="template-page-wrapper">
  <div class="navbar-collapse collapse templatemo-sidebar">
    <ul class="templatemo-sidebar-menu">
      <li>
        <form class="navbar-form">
          欢迎您:{{user.name || '访客'}}</span>
        </form>
      </li>
      <li ng-repeat="menu in menus" ng-class="menu.menuclass" ng-click="menuclick(menu)">
        <a ng-click="redi(menu.url)" ng-if="menu.items.length==0"><i ng-class="menu.icon"></i>{{menu.label}}</a>
        <a href="#" ng-if="menu.items.length>0">
          <i ng-class="menu.icon"></i> {{menu.label}} <div class="pull-right"><span class="caret"></span></div>
        </a>
        <ul class="templatemo-submenu" ng-if="menu.items.length>0">
          <li ng-repeat="item in menu.items" ng-click="redi(item.url)"><a href="javascript:void(0)">{{item.label}}</a></li>
        </ul>
      </li>
      <li>
        <a href="#" data-toggle="modal" data-target="#confirmModal"><i class="fa fa-sign-out"></i>退出登录</a>
      </li>
    </ul>
  </div><!--/.navbar-collapse -->

  <div class="templatemo-content-wrapper">
    <div class="templatemo-content">
      <ol class="breadcrumb">
        <li><a ng-click="redi('index.html')" href="javascript:void(0)">首页</a></li>
      </ol>
      <div class="row" ng-if="haserror">
        <div class="alert alert-danger alert-dismissible" role="alert">
          <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <strong>发生异常情况:{{errormessage}}</strong>
        </div>
      </div>

      <div class="row" ng-if="ids.length>0">
        <div class="alert alert-info alert-dismissible" role="alert">
          <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <button type="button" class="btn btn-success" ng-click="compare(test.id)">收益曲线比对</button>
          <strong>{{ids}}</strong>
        </div>
      </div>

      <div class="panel panel-primary">

        <div class="panel-body">
        <select ng-model="selectedStrategy" ng-options="v.label for (k,v) in eas" ng-change="query()"></select>
        </div>
        <h4 class="panel-heading">历史回测</h4>
        <table class="table table-striped table-hover table-bordered">
          <thead>
          <tr>
            <th style="width:46px">id</th>
            <th>测试名称</th>
            <th style="width:76px">策略名称</th>
            <th style="width:56px">版本</th>
            <th style="width:86px">测试用户</th>
            <th style="width:76px">初始金额</th>
            <th style="width:76px">最后金额</th>
            <th style="width:76px">总盈利率</th>
            <th style="width:96px">开始日期</th>
            <th style="width:96px">结束日期</th>
            <th style="width:46px">天数</th>
            <th style="width:76px">年化收益</th>
            <th style="width:46px">状态</th>
            <th style="width:190px">操作</th>
          </tr>
          </thead>
          <tbody>
          <tr ng-repeat="test in data.content">
            <td>{{test.id}}</td>
            <td>{{test.name}}</td>
            <td>{{test.strategyName}}</td>
            <td>{{test.version}}</td>
            <td>{{test.userName}}</td>
            <td>{{test.initMoney}}</td>
            <td>{{test.endMoney}}</td>
            <td>{{test.yields*100  | number : 2}}%</td>
            <td>{{test.beginDate | date: 'yyyy-MM-dd' }}</td>
            <td>{{test.endDate | date: 'yyyy-MM-dd' }}</td>
            <td>{{test.testDays }}</td>
            <td><font color="red"> {{test.yieldsPerDay*100*365 | number : 2}}%</font></td>
            <td>
              <img src="images/loading.gif" ng-if="!test.isEnd">
              <img src="images/A.png" ng-if="test.isEnd">
            </td>
            <td>
              <button type="button" class="btn btn-mini btn-success" ng-click="add(test.id)" ng-if="contain(test.id)">+</button>
              <button type="button" class="btn btn-mini btn-warning" ng-click="remove(test.id)" ng-if="!contain(test.id)">-</button>
              <button type="button" class="btn btn-mini btn-primary" ng-click="open('strategy_test_detail.html?id='+test.id)">🔍</button>
              <button type="button" class="btn btn-mini btn-info" ng-click="open('strategy_test_param.html?id='+test.id)">🔢</button>
              <button type="button" class="btn btn-mini btn-danger" ng-click="delete(test.id)">×</button>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <span ng-show="data.totalElements>0">共找到<font color="red">{{data.totalElements}}</font>条数据,分<font color="red">{{data.totalPages}}</font>页</span>
      <ul class="pagination pull-right">
        <li ng-class="firstclass" ng-show="!data.first"><a href="javascript:void(0)" ng-click="query(0)">&laquo;</a></li>
        <li ng-repeat="p in pages" ng-class="p.currentclass">
          <a ng-click="query(p.i)" href="javascript:void(0)">{{p.i}} <span class="sr-only">(current)</span></a>
        </li>
        <li ng-class="lastclass" ng-show="!data.last"><a href="javascript:void(0)" ng-click="query(data.totalPages-1)">&raquo;</a></li>
      </ul>
    </div>
  </div>

  <!-- Modal -->
  <div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
          <h4 class="modal-title" id="myModalLabel">确定退出吗</h4>
        </div>
        <div class="modal-footer">
          <a ng-click="logout()" class="btn btn-primary" data-dismiss="modal">确定</a>
          <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        </div>
      </div>
    </div>
  </div>

  <footer class="templatemo-footer">
    <div class="templatemo-copyright">
      <p>Copyright &copy; 2018 By <a href="http://skyquant.cn" title="天量科技" target="_blank">天量科技</a></p>
    </div>
  </footer>
</div>
</body>

<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/angular.js/1.5.8/angular.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/common.js"></script>
<script src="js/templatemo_script.js"></script>
<script type="text/javascript">
  'use strict';
  var app = angular.module('app', []);
  app.controller('index', ['$scope', '$http', function ($scope, $http) {

      //每个页面都要有的方法begin
      $scope.init = function(){
        getUser($http,$scope,'策略测试','策略管理');
      }

      $scope.logout = function(){
        logout($http);
      }

      $scope.menuclick=function(menu){
        changemenuclass($scope,menu);
      }

      $scope.redi=function(url){
          location.href = url;
      }

      $scope.open=function(url){
          window.open(url);
      }
      //每个页面都要有的方法begin

      //每个页面都需要重写此方法，发生在init之后
      $scope.initAfter = function(){
        $scope.query(0);
      }

      $scope.query = function(page){
        var selectStrategy = $scope.selectedStrategy.name;
        var url = 'quant4j-service/strategy_test/list?page='+page+'&size='+$scope.size ;
        if(selectStrategy!='all'){
          url += '&strategyName='+selectStrategy;
        }
        $scope.haserror = false;
        $http.get(url).success(function(data) {
            pagecommon($scope,data);
        }).error(ajaxerror);
      }

      $scope.delete = function(id){
        $http({method:'DELETE',url:'quant4j-service/strategy_test/'+id}).success(function(data,header,config,status) {
          if(data.ok){
            alert("删除成功");
            var currentpage=0;
            angular.forEach($scope.pages, function(page) {
              if(page.currentclass=='active'){
                currentpage = page.i;
              }
            });
            $scope.query(currentpage);
            $scope.haserror = false;
          }else{
            $scope.haserror = true;
            $scope.errormessage = data.message;
          }
        }).error(ajaxerror);
      }

      $scope.batchDelete = function(){
        /*
        $http({method:'DELETE',url:'quant4j-service/strategy_test/'+id}).success(function(data,header,config,status) {
          if(data.ok){
            alert("删除成功");
            var currentpage=0;
            angular.forEach($scope.pages, function(page) {
              if(page.currentclass=='active'){
                currentpage = page.i;
              }
            });
            $scope.query(currentpage);
            $scope.haserror = false;
          }else{
            $scope.haserror = true;
            $scope.errormessage = data.message;
          }
        }).error(ajaxerror);*/
      }

      $scope.compare = function(){
        if($scope.ids.length==0){
           $scope.haserror = true;
           $scope.errormessage = '至少选择一个测试结果';
        }else{
           var url = 'strategy_test_compare.html?ids=';
           var idstr = '';
           for(var i=0;i<$scope.ids.length;i++){
              var id = $scope.ids[i];
              if(i==0){
                idstr += id;
              }else{
                idstr += '_'+id;
              }
           }
           url += idstr;
           location.href = url;
        }
      }

      $scope.add = function(id){
        var i = $.inArray(id,$scope.ids);
        if(i<0){
          $scope.ids.push(id);
        }
      }

      $scope.remove = function(id){
        $scope.ids.remove(id);
      }

      $scope.contain = function(id){
        var i = $.inArray(id,$scope.ids);
        return i<0;
      }

      $scope.eas  = [
        {name : "all", label : "全部"},
        {name : "Apollo", label : "阿波罗"},
        {name : "Apollo", label : "阿修罗"},
        {name : "Athena", label : "雅典娜"}
      ];
      $scope.ids =[];
      $scope.selectedStrategy = $scope.eas[0];
      initPage($scope,20,10);
      $scope.init();
  }]);
</script>
</html>